package com.drug.web.controller.wms;

import com.drug.common.annotation.Log;
import com.drug.common.core.controller.BaseController;
import com.drug.common.core.domain.AjaxResult;
import com.drug.common.core.page.TableDataInfo;
import com.drug.common.enums.BusinessType;
import com.drug.common.utils.poi.ExcelUtil;
import com.drug.wms.domain.BusUnitConf;
import com.drug.wms.service.IBusUnitConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 单位配置Controller
 *
 * @author ruoyi
 * @date 2021-11-08
 */
@RestController
@RequestMapping("/wms/unit")
public class BusUnitConfController extends BaseController {
    @Autowired
    private IBusUnitConfService busUnitConfService;

    /**
     * 查询单位配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BusUnitConf busUnitConf) {
        startPage();
        List<BusUnitConf> list = busUnitConfService.selectBusUnitConfList(busUnitConf);
        return getDataTable(list);
    }

    /**
     * 导出单位配置列表
     */
    @Log(title = "单位配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusUnitConf busUnitConf) {
        List<BusUnitConf> list = busUnitConfService.selectBusUnitConfList(busUnitConf);
        ExcelUtil<BusUnitConf> util = new ExcelUtil<BusUnitConf>(BusUnitConf.class);
        return util.exportExcel(list, "单位配置数据");
    }

    /**
     * 获取单位配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(busUnitConfService.selectBusUnitConfById(id));
    }

    /**
     * 新增单位配置
     */
    @Log(title = "单位配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusUnitConf busUnitConf) {
        return toAjax(busUnitConfService.insertBusUnitConf(busUnitConf));
    }

    /**
     * 修改单位配置
     */
    @Log(title = "单位配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusUnitConf busUnitConf) {
        return toAjax(busUnitConfService.updateBusUnitConf(busUnitConf));
    }

    /**
     * 删除单位配置
     */
    @Log(title = "单位配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(busUnitConfService.deleteBusUnitConfByIds(ids));
    }
}
